package jsyf.oa.web.report.tomorrowPlan;

import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import jsyf.com.util.BaseUtils;
import jsyf.com.util.ResponseUtils;
import jsyf.oa.facade.weekplan.TomorrowPlanFacade;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Created by LT on 2018/5/14.
 */
@Api(value = "报表第二天计划接口", description = "报表第二天计划接口")
@Controller
@RequestMapping("/tomorrowPlan")
public class tomorrowPlanController {
    @Resource
    private TomorrowPlanFacade tomorrowPlanFacade;

    @ResponseBody
    @RequestMapping(value = "/getByUserIdAndDateTime.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "报表查询第二天计划",
            notes = "报表查询第二天计划 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "\"{userId:'201804052047404186626170CCC082F4'}\"", dataType = "String", paramType = "body")
    public void getByUserIdAndDateTime(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {

        List<JSONObject> records = this.tomorrowPlanFacade.getByUserIdAndDateTime(jsonData);
        if (records!= null) {
            ResponseUtils.putJsonResponse(response, BaseUtils.succsessArrRespond(records));
        } else {
            ResponseUtils.putJsonResponse(response, BaseUtils.errorrRespond("未找到数据"));
        }
    }


    @ResponseBody
    @RequestMapping(value = "/save.json", method = RequestMethod.POST)
    @ApiOperation(
            value = "补填第二天计划",
            notes = "补填第二天计划 ",
            httpMethod = "POST",
            produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiImplicitParam(name = "jsonData", value = "\"{userId:'201804052047404186626170CCC082F4'}\"", dataType = "String", paramType = "body")
    public void save(HttpServletRequest request, HttpServletResponse response, @RequestBody String jsonData) {
        String records = this.tomorrowPlanFacade.add(jsonData);
        ResponseUtils.putJsonResponse(response, BaseUtils.succsessObjRespond(records));
    }

}
